package com.example.springbootdemo.modules.user.controller;

import com.example.springbootdemo.modules.user.service.UserService;
import com.example.springbootdemo.po.User;
import com.example.springbootdemo.returns.JsonReturn;
import com.example.springbootdemo.util.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author: ShengXiaJia
 * @Date: 2020/2/17 16:06
 * @Description:
 */
@RestController
@RequestMapping("user")
public class UserController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    UserService userService;

    @Autowired
    private RedisUtil redis;

    @GetMapping(value = "add")
    public Object add(String name) {
        redis.set(name, name);
        return new JsonReturn().SUCCESS_JSON;

    }

    @RequestMapping("insert")
    public Object insert() {
        User user = new User("ss", 13, "1234567890", new Date(), new Date());
        return userService.insert(user);
    }

    @RequestMapping("getAll")
    public Object getAll() {
        return userService.getAll();
    }

    @RequestMapping("getById")
    public Object getById(Integer id) {
        return userService.getById(id);
    }

    @RequestMapping("update")
    public Object update(User user) {
        return userService.update(user);
    }

    @RequestMapping("delete")
    public Object delete(Integer id) {
        return userService.delete(id);
    }

}
